<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户注册页面</title>
    <link  rel="stylesheet" type="text/css" href="../css/xinxi.css">
</head>

<script type="text/javascript">
    function zc(){
        var name = from.name.value;
        if(name == ""){
            alert("亲，请输入用户名");
            return;
        }
        var inputpassword = from.inputpassword.value;
        if(inputpassword == ""){
            alert("亲，请输入密码");
            return;
        }
        var inputpasswordagin = from.inputpasswordagin.value;
        if(inputpasswordagin == ""){
            alert("亲，请输入确认密码");
            return;
        }
        if(inputpassword != inputpasswordagin){
            alert("亲，两次密码不一致");
            return;
        }
        var inputemal = from.inputemal.value;
        if(inputemal == ""){
            alert("亲，请输入邮箱");
            return;
        }
        var phone = from.phone.value;
        if(phone == ""){
            alert("亲，请输入手机号码");
            return;
        }
        var csny = from.csny.value;
        if(csny == ""){
            alert("亲，请输入出生年月");
            return;
        }
        var gzdw = from.gzdw.value;
        if(gzdw == ""){
            alert("亲，请输入工作单位");
            return;
        }
        var szdq = from.szdq.value;
        if(szdq == ""){
            alert("亲，请输入所在地区");
            return;
        }
        alert("恭喜你注册成功！");
        //跳转到登入
        window.location.href = "drym.php"
    }
</script>
<body>
<div class="top">

    <div class="top-left">
        <span>注册账号</span>
    </div>
    <div class="top-right">
        <p>我已注册，现在就<a href="drym.php">登入</a></p>
    </div>

</div>
<hr>
<div id="main">
    <form name="from" method="post" action="drym.php" >
        <!--注册页面的注册数据信息不少于8项-->
        用户类型：
        <br>
        <select name="1">
            <option value="1">普通用户</option>
            <option>管理员用户</option>
        </select>
        <br>
        用户名：
        <input class="srk" id="name" name="username" type="text">
        <br>
        登入密码：
        <input class="srk" name="inputpassword" type="password">
        <br>
        确认密码：
        <input class="srk" name="inputpasswordagin" type="password">
        <br>
        邮箱：
        <input  class="srk" name="inputemal" type="text">
        <br>
        手机号码：
        <input  class="srk" name="phone" type="text">
        <br>
        出生年月：
        <input  class="srk" name="csny" type="text">
        <br>
        工作单位：
        <input  class="srk" name="gzdw" type="text">
        <br>
        所在地区：
        <input  class="srk" name="szdq" type="text">
        <br>
        <input id="button_zc" name="button_zc" type="submit" value="注册">
    </form>
</div>
<br>
<br>
<br>
<footer style="text-align:center">
    <p>Copyright © 2019&nbsp;FirPE Project All Rights Reserved. </p>
</footer>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
    if(isset($_POST['button_zc'])){
        $name = $_POST['username'];
        $password = $_POST['inputpassword'];
        $inputpasswordagin = $_POST['inputpasswordagin'];
        $inputemal = $_POST['inputemal'];
        $phone = $_POST['phone'];
        $csny = $_POST['csny'];
        $gzdw = $_POST['gzdw'];
        $szdq = $_POST['szdq'];

        if($name == ""){
            echo "<script>alert('请输入用户名')</script>";
            exit();
        }
        if($password == ""){
            echo "<script>alert('请输入密码')</script>";
            exit();
        }
        if($inputpasswordagin == ""){
            echo "<script>alert('请重新输入密码')</script>";
            exit();
        }
        if($inputemal == ""){
            echo "<script>alert('请输入邮箱')</script>";
            exit();
        }
//测试验证邮箱
        if(verifyEmail($inputemal)== false){
            echo "<script>alert('电子邮箱格式不合法')</script>";
            exit();
        }
        if($phone == ""){
            echo "<script>alert('请输入手机号码')</script>";
            exit();
        }
        if($csny == ""){
            echo "<script>alert('请输入出生年月')</script>";
            exit();
        }
        if($gzdw == ""){
            echo "<script>alert('请输入工作单位')</script>";
            exit();
        }
        if($szdq == ""){
            echo "<script>alert('请输入所在地区')</script>";
            exit();
        }
        session_start();
        $_SESSION['username']=$name;
        $_SESSION['userpassword']=$password;
        echo "<script>alert('注册成功')</script>";
//跳转到主页面
        echo "<script>window.location.href = 'drym.php'</script>";
    }
}
function verifyEmail($str){
    $pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i';
    if(preg_match($pattern,$str)){
        return true;
    }else{
        return false;
    }
}
?>